package com.xiaoshuidi.cloud.module.rooms.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoshuidi.cloud.module.rooms.mapper.RoomSdiotDeviceMappingMapper;
import com.xiaoshuidi.cloud.module.rooms.pojo.RoomSdiotDeviceMapping;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author Feng
 * @date 2023/8/18
 */
@Repository
public class RoomSdiotDeviceMappingRepository extends ServiceImpl<RoomSdiotDeviceMappingMapper, RoomSdiotDeviceMapping> {

    /**
     * 根据roomIds 获取关联列表
     *
     * @param roomIds
     * @return
     */
    public List<RoomSdiotDeviceMapping> listByRoomIds(List<Long> roomIds) {
        LambdaQueryWrapper<RoomSdiotDeviceMapping> wrapper = Wrappers.lambdaQuery();
        wrapper.in(RoomSdiotDeviceMapping::getRoomHouseId, roomIds);
        return this.list(wrapper);
    }

    /**
     * 根据设备号获取关联
     *
     * @param deviceNo
     * @return
     */
    public RoomSdiotDeviceMapping getByDeviceNo(String deviceNo) {
        LambdaQueryWrapper<RoomSdiotDeviceMapping> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(RoomSdiotDeviceMapping::getDeviceNo, deviceNo);
        return this.getOne(wrapper);
    }
}
